<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>统算详情</title>
    <!-- 引入样式 -->
    <link rel="stylesheet" type="text/css" href="/assets/element-plus/index.css">
    <!-- 引入 Vue.js -->
    <script src="/assets/vue/vue.global.js"></script>
    <!-- 引入 Element Plus -->
    <script src="/assets/element-plus/index.full.js"></script>
    <!-- 引入 Axios -->
    <script src="/assets/axios/axios.js"></script>
    <!-- 引入自定义安全模块 -->
    <script src="/assets/oa/security.js"></script>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f0f2f5;
            margin: 0;
            padding: 20px;
        }

        .container {
            max-width: 800px;
            margin: 0 auto;
            background-color: #fff;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            padding: 20px;
        }

        h2 {
            margin-top: 0;
            font-size: 24px;
            color: #333;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 20px;
        }

        th, td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: left;
        }

        th {
            background-color: #f2f2f2;
        }

        .info-item {
            margin-bottom: 10px;
        }

        .info-label {
            font-weight: bold;
        }

        .info-value {
            margin-left: 10px;
        }
    </style>
</head>
<body>
<div id="app">

    <!-- 统算详情展示区域 -->
    <div class="container">
        <!-- 订单信息 -->
        <h2>订单信息</h2>
        <div v-if="bingVo.order.length > 0" v-for="(orderItem, index) in bingVo.order" :key="'order_' + index">
            <div class="info-item">
                <span class="info-label">订单ID:</span>
                <span class="info-value">{{ orderItem.orderid }}</span>
            </div>
            <div class="info-item">
                <span class="info-label">客户ID:</span>
                <span class="info-value">{{ orderItem.customerid }}</span>
            </div>
            <div class="info-item">
                <span class="info-label">管理员ID:</span>
                <span class="info-value">{{ orderItem.managerid }}</span>
            </div>
            <div class="info-item">
                <span class="info-label">订单状态:</span>
                <span class="info-value">{{ orderItem.orderstatus }}</span>
            </div>
            <div class="info-item">
                <span class="info-label">订单价格:</span>
                <span class="info-value">{{ orderItem.packagecost }} 元</span>
            </div>
        </div>
        <!-- 电话卡详情 -->
        <h2>电话卡详情</h2>
        <table v-if="bingVo.phoneCard.length > 0">
            <thead>
            <tr>
                <th>电话卡号码</th>
                <th>账单ID</th>
                <th>被呼电话卡</th>
                <th>被呼费用</th>
                <th>通讯时长</th>
                <th>话费</th>
                <th>账单创建时间</th>
            </tr>
            </thead>
            <tbody>
            <tr v-for="(billingItem, index) in bingVo.phoneCard" :key="'billing_' + index">
                <td>{{ billingItem.userPhone }}</td>
                <td>{{ billingItem.billID }}</td>
                <td>{{ billingItem.calledOperatorPhone }}</td>
                <td>{{ billingItem.calledPrice }} 元/分钟</td>
                <td>{{ billingItem.callDuration }} 分钟</td>
                <td>{{ billingItem.phoneCharge }} 元</td>
                <td>{{ formatTimestamp(billingItem.createTime) }}</td>
            </tr>
            </tbody>
        </table>
        <!-- 总金额 -->
        <h2>总金额</h2>
        <div class="info-item">
            <span class="info-label">{{ bingVo.order[0]?.customerid }}客户的总金额:</span>
            <span class="info-value">{{ bingVo.sum }} 元</span>
        </div>
    </div>

</div>

<script>
    const app = Vue.createApp({
        data() {
            return {
                bingVo: {
                    phoneCard: [],
                    order: [],
                    sum: 0
                }
            };
        },
        mounted() {
            this.fetchData();
        },
        methods: {
            fetchData() {
                // 获取客户详细信息数据
                const urlParams = new URLSearchParams(window.location.search);
                const customerId = urlParams.get('customerid');
                axios.post("/bill/billing", { customerid: customerId })
                    .then(response => {
                        // 将获取到的客户详细信息数据赋值给 bingVo 对象
                        console.info(response);
                        this.bingVo = response.data.data;
                    })
                    .catch(error => {
                        console.error("获取客户详细信息失败：" + error);
                    });
            },
            formatTimestamp(timestamp) {
                if (!timestamp) return ''; // 如果时间戳不存在，则返回空字符串
                const date = new Date(timestamp);
                const year = date.getFullYear();
                const month = (date.getMonth() + 1).toString().padStart(2, '0');
                const day = date.getDate().toString().padStart(2, '0');
                const hours = date.getHours().toString().padStart(2, '0');
                const minutes = date.getMinutes().toString().padStart(2, '0');
                const seconds = date.getSeconds().toString().padStart(2, '0');
                return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
            }
        }
    });

    app.mount("#app");
</script>

</body>
</html>
